package com.zhang.controller;

import cn.hutool.crypto.SecureUtil;
import com.sun.net.httpserver.HttpServer;
import com.zhang.entity.User;
import com.zhang.service.UserService;
import com.zhang.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @GetMapping("/login/{username}/{password}")
    public R login(@PathVariable String username,
                   @PathVariable String password) {
        // 根据信息返回运行结果对应的信息提醒

        User user = userService.login(username, password);

        if (user == null) {
            return R.error("对不起，用户不存在！！");
        }
        // 使用md5加密密码
        String newPassword = SecureUtil.md5(password);
        if (user.getPassword().equals(newPassword)) {
            return R.ok("登录成功~");

        }else {
            return R.error("对不起，您的密码输入错误，请重新输入");
        }
    }

}
